<?php

class Core_Backend_Component_Permission_View_Accredit_Action_Create extends Core_Backend_Share_View_Form {

    protected function initialize(){
        parent::initialize();
        $this->setTemplatePath('edit');
    }

    protected function buildToolbar($toolbar){
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('permission/accredit_action/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.apply'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'apply')."')");
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar); 	
    }

    protected function buildForm($form){
    	$entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
             ->setId('accredit_form')
	     ->addHiddenField('id', 'accredit[id]')
             ->addHiddenField('area_id', 'accredit[area_id]', $this->getArea()->getId());
        $form->addTextboxField($this->__('share.label.component'), 'component_name', 'accredit[component_name]', TRUE)
             	->addRequiredRule();
        $form->addTextboxField($this->__('share.label.controller'), 'controller_name', 'accredit[controller_name]', TRUE);
        $form->addTextboxField($this->__('share.label.action'), 'action_name', 'accredit[action_name]', TRUE);
        $form->addSelectField($this->__('permission.label.accessControl'), 'access_control', 'accredit[access_control]', TRUE)
                ->setOption($this->__('permission.label.anonymousAccess'), 'anonymous')
                ->setOption($this->__('permission.label.loginAccess'), 'login')
                ->setOption($this->__('permission.label.allowRoleAccess'), 'allow_role')
                ->setOption($this->__('permission.label.adminAccess'), 'admin')
                ->addRequiredRule();
        $form->addComboTreeField($this->__('permission.label.role'), 'role_ids', 'accredit[role_ids][]', TRUE)
		->bindData($this->getRoles()->toArray(), 0, array('valueKey'=>'id', 'textKey'=>'name', 'parentKey'=>'parent_id', 'childKey'=>'id'))
                ->setMultiple(TRUE)
                ->setSize(10)
                ->getField()
                ->setHidden(TRUE);
        if(!is_null($entity)){
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }
}